package com.qf.service.impl;

import com.qf.service.ShibieService;
import com.qf.utils.GsonUtils;
import com.qf.utils.HttpUtil;
import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Service
public class ShibieServiceImpl implements ShibieService {
    @Override
    public String faceSearch(String image, String accessToken, String username) {
        // 请求url
        String url = "https://aip.baidubce.com/rest/2.0/face/v3/search";

        try {
            Map<String, Object> map = new HashMap<>();
            map.put("image", image);
            map.put("group_id_list", "test1");
            map.put("user_id", username);
            map.put("image_type", "BASE64");

            String param = GsonUtils.toJson(map);

            // 注意这里仅为了简化编码每一次请求都去获取access_token，线上环境access_token有过期时间， 客户端可自行缓存，过期后重新获取。
            //String accessToken = "[调用鉴权接口获取的token]";

            String result = HttpUtil.post(url, accessToken, "application/json", param);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
